import React from 'react'
import { HashRouter as Router, Redirect, Route, Switch } from 'react-router-dom'
import Home from 'pages/Home'
import City from 'pages/City'
import Map from 'pages/Map'
import Detail from 'pages/Detail'
import Login from 'pages/Login'
import Rent from 'pages/Rent'
import NoMatch from 'pages/NoMatch'
import PrivateRoute from 'common/PrivateRoute'

class App extends React.Component {
  render() {
    return (
      <Router>
        <div className="app">
          {/* react中路径匹配, 都是模糊匹配, redirect如果配置了 /, 一定要加 exact */}
          {/* Redirect使用时, 必须要放在Switch中, 不然from不生效 */}
          <Switch>
            <Redirect exact from="/" to="/home"></Redirect>
            <Route path="/home" component={Home}></Route>
            <Route path="/city" component={City}></Route>
            <Route path="/map" component={Map}></Route>
            <Route path="/login" component={Login}></Route>

            <PrivateRoute path="/rent" component={Rent}></PrivateRoute>
            <Route path="/detail/:id" component={Detail}></Route>
            <Route component={NoMatch}></Route>
          </Switch>
        </div>
      </Router>
    )
  }
}

export default App
